<?php
// Display the results of the top 10 swimmers given the age, gender, type, length
// from the link that the user clicks on from the sliding menu.
include("../../includes/dbInfo.php");
$group = $_GET["group"];
$gender = $_GET["gender"];
$type = $_GET["type"];
$length = $_GET["length"];

$query = "SELECT `ls_events`.`name` AS eName, `ls_events`.`name` AS eName,
		`ls_events`.`eventDate` AS date, `swimPerformance`.`place` AS place,
		`swimPerformance`.`time` AS time, `accounts`.`name` AS name
		FROM `ls_events`, `swimPerformance`, `accounts`
		WHERE `ls_events`.`eventID` = `swimPerformance`.`eventID`
		AND `swimPerformance`.`swimmerID` = `accounts`.`userID`
		AND `ls_events`.`ageGroup` = '$group'
		AND `ls_events`.`gender` = '$gender'
		AND `ls_events`.`eventType` = '$type'
		AND `ls_events`.`eventLength` = '$length'
		ORDER BY time ASC LIMIT 10";
$result = mysql_query($query) or die("Error on getting events: " . mysql_error());
if(mysql_num_rows($result) == 0) {
	echo "<p>No swimmers participated in this event.</p>";
}
// Display the table of the top 10 swimmers.
else {
	echo "<table id='blueTable'><tr><th>Swimmer Name</th><th>Event</th><th>Date</th><th>Time</th><th>Place</th></tr>";
	$i = 0;
	while($rows = mysql_fetch_assoc($result)) {
		$style = (($i % 2) == 0) ? "even" : "odd";
		echo "<tr class='$style'><td>" . $rows["name"] . "</td><td>" . $rows["eName"] . "</td><td>" . 
		$rows["date"] . "</td><td>" . $rows["time"] . "</td><td>" . $rows["place"] . "</td></tr>";
		$i++;
	}
	echo "</table>";
}
?>